// by Xeno
#define __ctrl(vctrl) _ctrl = _XD_display displayCtrl vctrl
private ["_ctrl","_current_mission_id","_ok","_s","_has_mission","_XD_display","_start_pos","_end_pos","_isadmin","_mission_pos","_mission_array","_current_mission_completed"];
if (!X_Client) exitWith {};

disableSerialization;

_ok = createDialog "XD_StatusDialog";

_XD_display = uiNameSpace getVariable "X_STATUS_DIALOG";

_isadmin = player getVariable "d_p_isadmin";
if (isNil "_isadmin") then {_isadmin = false};

__ctrl(11015);
_ctrl ctrlSetText missionName;

if (!_isadmin And !PublicMissionScreen) then {
	// Hides the mission dialog button for non admins
	__ctrl(123122);
	_ctrl ctrlShow false;
};
if (!_isadmin) then {
	// Hides the admin dialog button for non admins
	__ctrl(123123);
	_ctrl ctrlShow false;
};

_current_mission_id = ["current_mission_id",-1] call XNetGetJIP;
_current_mission_completed = ["current_mission_completed",true] call XNetGetJIP;
_has_mission = false;
diag_log Format["(%1)[%2]: %3: %4, %5",diag_tickTime,"showstatus.sqf","Current Mission Info",_current_mission_id,_current_mission_completed];
If ((!isNil "_current_mission_id") AND (!isNil "_current_mission_completed")) then {
	If (_current_mission_id >= 0 AND (!_current_mission_completed)) then {
		diag_log Format["(%1)[%2]: %3: %4",diag_tickTime,"showstatus.sqf","Available missions",(["available_missions",[]] call XNetGetJIP)];
		If (count (["available_missions",[]] call XNetGetJIP) > _current_mission_id) then {
			_mission_array = (["available_missions",[]] call XNetGetJIP) select _current_mission_id;
			__ctrl(11007);
			_ctrl ctrlSetText ((_mission_array select 1) call XfTranslate);
			__ctrl(11002);
			_ctrl ctrlSetText ((_mission_array select 2) call XfTranslate);
			__ctrl(11018);
			_ctrl ctrlSetText ((_mission_array select 3) call XfTranslate);
			_has_mission = true;
		};
	};
};
If (!_has_mission) then {
	__ctrl(11007);
	_ctrl ctrlSetText localize "MSG_DOM_MFNOMISSIONRUNNING";
	__ctrl(11002);
	_ctrl ctrlSetText localize "MSG_DOM_MFMISSIONHELP";
	__ctrl(11018);
	_ctrl ctrlSetText "";
};

_s = format [localize "MSG_DOM_WEATHERCONDITION", round(overcast * 100), round (rain * 100)];
__ctrl(11013);
_ctrl ctrlSetText _s;

__ctrl(11009);
if (!d_use_teamstatusdialog) then {
	_ctrl ctrlShow false;
} else {
	if (vehicle player == player) then {
		_ctrl ctrlSetText localize "MSG_DOM_STATUSTEAM";
	} else {
		_ctrl ctrlSetText localize "MSG_DOM_STATUSVEC";
	};
};

__ctrl(11015);
_ctrl ctrlSetText getText (missionConfigFile >> "onLoadMission");

_end_pos = [];
_mission_pos = ["current_mission_position",[[0,0,0],0,""]] call XNetGetJIP;
diag_log Format["(%1)[%2]: %3: %4",diag_tickTime,"showstatus.sqf","Current Mission Position",_mission_pos];
If (count _mission_pos > 0) then {
	If (Format["%1",_mission_pos select 0] != "[0,0,0]") then {
		_end_pos = _mission_pos select 0;
	};
};
diag_log Format["(%1)[%2]: %3: %4",diag_tickTime,"showstatus.sqf","Current Mission Position",_end_pos];
If (count _end_pos > 0) then {
	sleep 1;
	_start_pos = position FLAG_BASE;
	__ctrl(11010);
	_ctrl ctrlmapanimadd [0.0, 1.00, _start_pos];
	_ctrl ctrlmapanimadd [1.2, 1.00, _end_pos];
	_ctrl ctrlmapanimadd [0.5, 0.30, _end_pos];
	ctrlmapanimcommit _ctrl;
};
waitUntil {!dialog || !alive player};

if (!alive player) then {closeDialog 0};